<!--页面主要内容-->
<main class="lyear-layout-content">

	<div class="container-fluid p-t-15">

		<div class="row">
			<div class="col-lg-12">
				<div class="card">
					<div class="card-toolbar d-flex flex-column flex-md-row">
						<div class="toolbar-btn-action">
							<a class="btn btn-success" onclick="back()" href="#!"><i class="mdi mdi-check"></i>返回</a>
							<a class="btn btn-danger" id="delrecord" href="#!"><i class="mdi mdi-window-close"></i>删除</a>
						</div>

						<form class="search-bar ml-md-auto" method="get" action="#!" role="form">
							<input type="hidden" name="search_field" id="search-field" value="title" />
							<div class="input-group ml-md-auto">
								<div class="input-group-prepend">
									<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"
										aria-haspopup="true" aria-expanded="false" id="search-btn">标题</button>
									<div class="dropdown-menu" style="">
										<a class="dropdown-item" href="#!" data-field="title">标题</a>
										<a class="dropdown-item" href="#!" data-field="cat_name">栏目</a>
									</div>
								</div>
								<input type="text" class="form-control" name="keyword" placeholder="请输入名称">
							</div>
						</form>
					</div>
					<div class="card-body">

						<div class="table-responsive">
							<table class="table table-bordered">
								<thead>
									<tr style="text-align: center;">
										<th>
											<div class="custom-control custom-checkbox">
												<input type="checkbox" class="custom-control-input" id="check-all">
												<label class="custom-control-label" for="check-all"></label>
											</div>
										</th>
										<th>积分变化</th>
										<th>消费时间</th>
										<th>消费描述</th>
										<th>消费状态</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody style="text-align: center;">
									{foreach $recordlist as $item}
									<tr>
										<td>
											<div class="custom-control custom-checkbox">
												<input type="checkbox" class="custom-control-input ids" name="ids[]"
													value="{$item.id}" id="{$item.id}">
												<label class="custom-control-label" for="{$item.id}"></label>
											</div>
										</td>
										<td>{$item['point']}</td>
										<td>{$item['createtime']}</td>
										<!-- <td><textarea style="border:none;outline: none;resize: none;">{$item['content']}</textarea></td> -->
										<td>{$item['content']}</td>
										<td>
											{if condition="$item['state'] == 1"}
											<span class="badge badge-success">发布</span>
											{elseif condition="$item['state'] == 2"}
											<span class="badge badge-success">采纳</span>
											{elseif condition="$item['state'] == 3"}
											<span class="badge badge-success">充值</span>
											{elseif condition="$item['state'] == 4"}
											<span class="badge badge-success">签到</span>
											{elseif condition="$item['state'] == 5"}
											<span class="badge badge-success">下商品订单</span>
											{elseif condition="$item['state'] == 6"}
											<span class="badge badge-success">下预约订单</span>
											{else/}
											<span class="badge badge-primary">所有类型退款</span>
											{/if}
										</td>
										
										<td>
																  
											<div class="btn-group">
												<a class="btn btn-xs btn-default ajax-get confirm delrecords" data-id="{$item.id}" href="#" title="" data-toggle="tooltip" data-original-title="删除"><i class="mdi mdi-window-close"></i></a>
											</div>
										</td>
										
									</tr>
									{/foreach}

								</tbody>
							</table>
						</div>


						<!-- 分页 -->
						{$recordlist->render()}

					</div>
				</div>
			</div>

		</div>

</main>
<!--End 页面主要内容-->
<script type="text/javascript">

	function GetId() {
		// 存放id的数组
		let list = []

		$('input[name="ids[]"]:checked').each(function() {
			// console.log(item);
			list.push($(this).val())
		})

		return list
	}

	layui.use(['layer'], function() {
		layer = layui.layer


		// 删除消费记录
		$('#delrecord').click(function() {

			let str = GetId().join(',');

			$.ajax({
				type: 'post',
				url: `{:url('admin/user/delrecord')}`,
				data: {
					str
				},
				dataType: 'json',
				success: function(res) {
					if (res.code === 1) {
						layer.msg(res.msg, {
							icon: 1
						}, function() {
							location.href = 'userlist';
						})
					} else {
						layer.msg(res.msg, {
							icon: 5
						})
					}
				}
			})

		})
		
		// 删除单条消费记录
		$('.delrecords').click(function(){
			
			let id = $(this).data('id');
			
			$.ajax({
				type:'post',
				url:`{:url('admin/user/delrecords')}`,
				data:{
				  id
				},
				dataType:'json',
				success:function(res)
				{
				  if(res.code === 1)
				  {
					layer.msg(res.msg,{icon: 1},function(){
					 
					  location.href = 'userlist';
					})
				  }else{
					layer.msg(res.msg,{icon: 5})
				  }
				}
			})
			
		})

	})
	
	//返回上个页面
	function back() {
	    console.log("点击了后退");
	    //window.history.back();
	    //plus.webview.currentWebview().close();
	    if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)) { // IE
	        if (history.length > 0) {
	            window.history.go(-1);
	            console.log("IE浏览器 点击了后退");
	        } else {
	            console.log("IE浏览器 返回到源生");
	            window.open('baidu://backWebView');
	        }
	    } else { //非IE浏览器
	        if (navigator.userAgent.indexOf('Firefox') >= 0 ||
	            navigator.userAgent.indexOf('Opera') >= 0 ||
	            navigator.userAgent.indexOf('Safari') >= 0 ||
	            navigator.userAgent.indexOf('Chrome') >= 0 ||
	            navigator.userAgent.indexOf('WebKit') >= 0) {
	
	            if (window.history.length > 1) {
	                window.history.go(-1);
	                console.log("非IE浏览器 点击了后退");
	            } else {
	                window.open('baidu://backWebView');
	                console.log("非IE浏览器 返回到源生");
	            }
	        } else { //未知的浏览器
	            window.history.go(-1);
	            console.log("未知的浏览器 点击了后退");
	        }
	    }
	}
	
</script>
